/**
 * zmn产品模块-产品列表
 * @author tanghongjun
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        defaultToolbar: ['filter', 'exports'], done: function () {
            $("div[lay-event='LAYTABLE_EXPORT']").attr('lay-event', 'CUSTOM_EXPORT');
        },
        page: true,
        limit: json.pageSize,
        height: 'full-149'
    });
    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    let ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function (obj) {
        ids = table.checkStatus('zmn-table').data.map((item) => item.relateId);
    });

    form.on('submit(query-export)', function (data) {
        let index = layer.load(1, {
            shade: [0.5, '#DBDBDB'] //0.1透明度的白色背景
        });
        zmnUtil.downloadLimitByConfig("/product/businessline/outputExcel.action?" + $("#product_businessline_list").serialize(), "业务线报表.xlsx", function () {
            layer.close(index);
        });
        return false;
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        switch (obj.event) {
            case 'CUSTOM_EXPORT':
                $("#query-export").click();
                return;
            case 'stop':
            case 'start':
                if (ids.length === 0) {
                    return layer.alert("请选择至少1条数据！");
                }
                zmnPage.layStartStop(obj, "/product/businessline/updateStatus.action", ids.join(","));
            default: return;
        }
    });

    // 修改排序
    table.on("edit(zmn-table)", function (obj) {
        zmnPage.laySort(obj, "/product/businessline/updateSort.action", obj.data.relateId);
    });

    //对外暴露的接口
    exports('plat_businessline_list', {});
});

function toaddBusinessLine(){
    layer.open({
        type: 2,
        title:'新增业务线',
        area: ['580px', '330px'],
        content: '/product/businessline/addEditView.action'
    });

}

function toEditBusinessLine(groupId){
    layer.open({
        type: 2,
        title:'修改业务线',
        area: ['580px', '380px'],
        content: '/product/businessline/addEditView.action?relateId='+groupId
    });

}
